package com.itboye.textileexpes.presenter;

import java.util.List;
import java.util.Observer;

import android.util.Log;

import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.textileexpes.beans.ReceiveAddressBean;
import com.itboye.textileexpes.beans.ShopCartModel;
import com.itboye.textileexpes.interfaces.IReceiveAddress;
import com.itboye.textileexpes.interfaces.IShopCart;
import com.itboye.textileexpes.repository.ReceiveAddressRepository;
import com.itboye.textileexpes.repository.ShopCartRepository;
import com.itboye.textileexpres.base.BasePresenter;
import com.itboye.textileexpres.base.ResultEntity;

public class ShopCartPresenter extends BasePresenter implements
		IShopCart<ShopCartModel> {
	public static final String QueryShopCartSuccessEvent = MainPresenter.class
			.getName() + "_QueryShopCart_success";
	public static final String QueryShopCartFailureEvent = MainPresenter.class
			.getName() + "_QueryShopCart_failure";
	public static final String AddShopCartSuccessEvent = MainPresenter.class
			.getName() + "_AddShopCart_success";
	public static final String AddShopCartFailureEvent = MainPresenter.class
			.getName() + "_AddShopCart_failure";
	public static final String DeleteShopCartSuccessEvent = MainPresenter.class
			.getName() + "_DeleteShopCart_success";
	public static final String DeleteShopCartFailureEvent = MainPresenter.class
			.getName() + "_DeleteShopCart_failure";
	public static final String UpdateShopCartSuccessEvent = MainPresenter.class
			.getName() + "_UpdateShopCart_success";
	public static final String UpdateShopCartFailureEvent = MainPresenter.class
			.getName() + "_UpdateShopCart_failure";
/***
 * 
 * @param 订单
 */
	public static final String ShopcarOrderSuccessEvent = MainPresenter.class
			.getName() + "_ShopcarOrder_success";
	public static final String ShopcarOrderFailureEvent = MainPresenter.class
			.getName() + "_ShopcarOrder_failure";
	public ShopCartPresenter(Observer observer) {
		super(observer);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void add(ShopCartModel model) {
		// TODO Auto-generated method stub
		IShopCart<ShopCartModel> shop = new ShopCartRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						Log.v("MainPresenter", "register success");
						result.setEventTag(Tag_Success);
						result.setEventType(AddShopCartSuccessEvent);
						ShopCartPresenter.this.setChanged();
						ShopCartPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						Log.v("MainPresenter", "register failure");
						result.setEventTag(Tag_Error);
						result.setEventType(AddShopCartFailureEvent);
						ShopCartPresenter.this.setChanged();
						ShopCartPresenter.this.notifyObservers(result);
					}
				});
		shop.add(model);
	}

	@Override
	public void delete(ShopCartModel model) {
		// TODO Auto-generated method stub
		IShopCart<ShopCartModel> shop = new ShopCartRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						Log.v("MainPresenter", "register success");
						result.setEventTag(Tag_Success);
						result.setEventType(DeleteShopCartSuccessEvent);
						ShopCartPresenter.this.setChanged();
						ShopCartPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						Log.v("MainPresenter", "register failure");
						result.setEventTag(Tag_Error);
						result.setEventType(DeleteShopCartFailureEvent);
						ShopCartPresenter.this.setChanged();
						ShopCartPresenter.this.notifyObservers(result);
					}
				});
		shop.delete(model);
	}

	@Override
	public void update(ShopCartModel model) {
		// TODO Auto-generated method stub
		IShopCart<ShopCartModel> shop = new ShopCartRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						Log.v("MainPresenter", "register success");
						result.setEventTag(Tag_Success);
						result.setEventType(UpdateShopCartSuccessEvent);
						ShopCartPresenter.this.setChanged();
						ShopCartPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						Log.v("MainPresenter", "register failure");
						result.setEventTag(Tag_Error);
						result.setEventType(UpdateShopCartFailureEvent);
						ShopCartPresenter.this.setChanged();
						ShopCartPresenter.this.notifyObservers(result);
					}
				});
		shop.update(model);
	}

	@Override
	public void getInfo(ShopCartModel model) {
		// TODO Auto-generated method stub
		IShopCart<ShopCartModel> shop = new ShopCartRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						Log.v("MainPresenter", "register success");
						result.setEventTag(Tag_Success);
						result.setEventType(QueryShopCartSuccessEvent);
						ShopCartPresenter.this.setChanged();
						ShopCartPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						Log.v("MainPresenter", "register failure");
						result.setEventTag(Tag_Error);
						result.setEventType(QueryShopCartFailureEvent);
						ShopCartPresenter.this.setChanged();
						ShopCartPresenter.this.notifyObservers(result);
					}
				});
		shop.getInfo(model);
	}

	@Override
	public List<ShopCartModel> query(ShopCartModel model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onShopCharOrder(String uid, String page_size, String page_index) {

		IShopCart<ShopCartModel> shop = new ShopCartRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						Log.v("MainPresenter", "register success");
						result.setEventTag(Tag_Success);
						result.setEventType(ShopcarOrderSuccessEvent);
						ShopCartPresenter.this.setChanged();
						ShopCartPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						Log.v("MainPresenter", "register failure");
						result.setEventTag(Tag_Error);
						result.setEventType(ShopcarOrderFailureEvent);
						ShopCartPresenter.this.setChanged();
						ShopCartPresenter.this.notifyObservers(result);
					}
				});
		shop.onShopCharOrder(uid, page_size, page_index);
	}

}
